import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../msg/room_msg.dart';
import 'message_input_bar.dart';

class MessageInputOverlay extends ModalRoute<String> {
  InputCallback onInput;
  bool showEmoji;
  RoomMsg? quoteMsg;

  MessageInputOverlay(
      {required this.onInput, this.showEmoji = false, this.quoteMsg});

  static Future<String?> show(BuildContext context, InputCallback onInput,
      {bool showEmoji = false, RoomMsg? quoteMsg}) async {
    return Navigator.of(context).push(MessageInputOverlay(
        onInput: onInput, showEmoji: showEmoji, quoteMsg: quoteMsg));
  }

  dismiss(
    BuildContext context,
  ) {
    Navigator.pop(context);
  }

  @override
  Color? get barrierColor => const Color(0x01000000);

  @override
  bool get barrierDismissible => true;

  @override
  String? get barrierLabel => null;

  @override
  Widget buildPage(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation) {
    return MessageInputBar(
      onInputFinish: onInput,
      showEmoji: showEmoji,
      quoteMsg: quoteMsg,
    );
  }

  @override
  Widget buildTransitions(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation, Widget child) {
    return FadeTransition(
      opacity: CurvedAnimation(parent: animation, curve: Curves.easeOut),
      child: child,
    );
  }

  @override
  bool get maintainState => true;

  @override
  bool get opaque => false;

  @override
  Duration get transitionDuration => const Duration(microseconds: 200);
}
